package com.cjzuji.rental.controller.order;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cjzuji.rental.mapper.RequestMapper;
import com.cjzuji.rental.pojo.RequestHeard;
import com.cjzuji.rental.service.YpRiskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/order/yp")
@Api(tags = "优品风控")
@Component
public class YpRiskController {
    @Autowired
    RequestMapper requestMapper;
    @Autowired
    YpRiskService ypRiskService ;

    private static final Logger logger = LoggerFactory.getLogger(YpRiskController.class);

    //http://127.0.0.1:9099/order/yp/getRiskInfo
    //获取所有数据
    @GetMapping("/getRiskInfo")
    @ApiOperation(value = "获取风控详情", notes = "优品风控详情")
    //@Scheduled(fixedRate = 5 * 60 * 1000)
    public List<Map<String, Object>> getOrderList() {
        //从数据库获取
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String accesstoken = requestHeard.getAccesstoken();
            String authorization = requestHeard.getAuthorization();
            List<Map<String, Object>> result = ypRiskService.getOrderssList(accesstoken, authorization);
            return result;
        } catch (Exception e) {
            logger.error("获取 优品风控 所有订单列表详情失败");
            return null;
        }
    }
}